<template>
  <div class="home por">
    <div class="form_container center">
      <div class="form_title">
        <div class="logo"><span class="icon"></span></div>
        <div class="title">欢迎登录企业网银ERP系统</div>
      </div>
      <el-form :model="ruleForm" status-icon :rules="rules2" ref="ruleForm" class="demo-ruleForm">
        <el-form-item prop="user">
          <el-input
            type="text"
            v-model="ruleForm.user"
            auto-complete="off"
            placeholder="请输入用户名"
          >
            <i slot="prefix" class="icon iconfont icon-xingmingyonghumingnicheng"></i>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            type="password"
            v-model="ruleForm.password"
            auto-complete="off"
            placeholder="请输入密码"
          >
            <i slot="prefix" class="icon iconfont icon-mima"></i>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">登 录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { getAccessToken } from '@/libs/api.js';
import { mapActions, mapState } from 'vuex';

export default {
  data () {
    return {
      ruleForm: {
        user: '',
        password: ''
      },
      rules2: {
        user: [{ required: true, message: '请输入用户名', trigger: 'change' }],
        password: [{ required: true, message: '请输入用户名', trigger: 'change' }]
      }
    }
  },
  methods: {
    ...mapActions(['setToken']),
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const params = {
            appKey: 'APP-SlKknS5oPAVj48tTSlnSfKrrnWoG6Onz',
            appSecret: 'XOFx652vqeY3m4xw',
            privateKey: 'MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAL6MeCrnjXQkJVyY0yLSgg4QrEtvAogDD5D4xxAcnsHOlWnN2sevMXk1k+I2YJRZ6JOSmuCVoBKCHk7Catr4ixP088/1dhTvvX/yuA/7u/op74lRzpCkN3vLdwMX0vBj+cOwwbZAcuQ44ytHVYJo7A1lUZgJfgljILY/00vOLXxnAgMBAAECgYEAkcI6GffOiM0tl0uAFt8YhVHTulBMi2Zr/eWPwI9kEbTJLoo9lQo6uhF18lDOSC0Ob/RxbOKH9CB8tpqZyq7dEzD7EU5X+sObqD0WnNsX6ISmpk0k7N5PkSJQQvcQUZGQOtOUX3pqKerv+MZIwc1r/u6FeiO2fCe+lif1GcP34GECQQDjrTIwsGubjrGpqN454Xltdl4ShLzYkxoVLYnkg5Zv80pu+RpyIgkKWKTpcd65XGrZ4WIZFksZEgnzJxZLM7xzAkEA1kDdaLnEjxRLJWv1rOmzrQ5OGFw4j6s/aDYfmD0mBUF2UQvGPLCh4YurklCsYEx44hAvMUE9p6fwy6pXadfXPQJAIhZIMWn4cm3Gw7P4sYnEeFMEeplM/M/pU8phnsjkuRYfysWY5AWcfOQQrLLTucTQapaH7WGdFL/SpYjwmYnBaQJBAIBgy4olzZ5B9akNoF6khfHK4YZ9M7L6VHr3+0R4V2DM0b1MRdM1rzn7O6nnRvJIwCIMuopT4kKkQYd3oPsdxq0CQQCXNbRvb9OsOQuiuK/Msem+gHottSHeZ/XdiUuJ/lGxc9SLjxJQp4U7/4JL6kmuC5pqWo44/mdje6jUQE/o5BWR'
          }
          getAccessToken(params).then(res => {
            this.setToken(res.accessToken)
            this.$router.replace({path: '/home'})
          })
        } else {
          this.$notify({
            title: '',
            message: '请确认输入项是否正确',
            type: 'warning'
          });
          return false
        }
      })
    }
  },
  computed: {
    ...mapState(['token'])
  }
}
</script>

<style scoped lang = 'less'>
.home {
  width: 100%;
  height: 100%;
  background-image: url(../assets/bk.svg);
  background-repeat: no-repeat;
  .form_container {
    padding: 16px;
    border-radius: 4px;
    width: 440px;
    background: #FFF;
    box-shadow: 0 0 15px 5px #DDD;;
    .form_title {
      text-align: center;
      margin-bottom: 16px;
      .logo {
        .icon {
          width: 50px;
          height: 50px;
          display: inline-block;
          background-image: url('../assets/logo.svg');
          background-size: 50px 50px;
        }
      }
      .title {
        height: 45px;
        line-height: 45px;
        font-size: 24px;
        font-weight: 500;
        color: rgba(0, 0, 0, 0.85);
      }
    }
    .demo-ruleForm {
      min-width: 50%;
      .el-button--primary {
        width: 100%;
      }
    }
  }
}
@media screen and (max-width:600px){
  .home{
    .form_container{
      width: 70%;
      .form_title .title {
        font-size: 18px;
        font-weight: 400;
      }
    }
  }
}
</style>
